@extends('layouts.default')

@section('title', '论文发表')

@push('scripts')
<script src="{{ asset('lib/xm-select-v1.2.4/xm-select.js')}}"></script>
<script>
    layui.use(['layer','form','table','laytpl','laydate','element','laypage','upload'], function(){
        var layer = layui.layer;
        var form = layui.form;
        var table = layui.table;
        var laytpl = layui.laytpl;
        var laydate = layui.laydate;
        var element = layui.element;
        var laypage = layui.laypage;
        var upload = layui.upload;
        var kwfmFiles = [];
        var xmDemo;
        var PageId = "{{request()->get('id',0)}}";

        renderSelect();

        laydate.render({
            elem: '#publish-date'
            ,type: 'date'
        });
        laydate.render({
            elem: '#award-date'
            ,type: 'date'
        });

        //下拉框初始化
        async function renderSelect(){
            await renderDictionarySelect();
            await renderTermSelect();
            await renderParticipants();
            pageInit();
        }

        //字典下拉框数据渲染
        function renderDictionarySelect() {
            return new Promise((resolve) => {
                getDictionaryItem({'diccode': ['LEVEL']}, function (res){
                    if(res.code === 1) {
                        let data = res.data;

                        for(var k in data) {
                            let key = k.toLowerCase();
                            let d = data[k];

                            $('[data-role='+key+'List]').empty().append('<option value="">请选择</option>');
                            for (var i in d) {
                                $('[data-role='+key+'List]').append('<option value="' + d[i].optionId + '">' + d[i].selectValue + '</option>');
                            }
                        }

                        form.render();

                        resolve();
                    }
                });
            });
        }

        //学期下拉框数据渲染
        function renderTermSelect() {
            return new Promise((resolve) => {
                getTermData({},function(res){
                    if(res.code == 1){
                        $('[data-role=termList]').empty().append('<option value="">请选择</option>');
                        for(var i in res.data){
                            $('[data-role=termList]').append('<option value="'+res.data[i].id+'">'+res.data[i].title+'</option>');
                        }

                        form.render('select');

                        resolve();
                    }
                });
            });
        }

        //参与教师下拉框数据渲染
        function renderParticipants() {
            return new Promise((resolve) => {
                getParticipantsData({},function(res){
                    if(res.code == 1){
                        xmDemo = xmSelect.render({
                            el: '#pter',
                            autoRow: true,
                            filterable: true,
                            tree: {
                                show: true,
                                showFolderIcon: true,
                                showLine: true,
                                indent: 20,
                                expandedKeys:false
                            },
                            direction: 'down',
                            filterable: true,
                            height: 'auto',
                            name:'participant',
                            layVerify: 'required',
                            layVerType: 'msg',
                            layReqText:'参与教师不能为空',
                            theme: {
                                color: '#2d8cf0',
                            },
                            model: {
                                label: {
                                    type: 'block',
                                    block: {
                                        //最大显示数量, 0:不限制
                                        showCount: 0,
                                        //是否显示删除图标
                                        showIcon: false,
                                    }
                                }
                            },
                            disabled:true,
                            searchTips:'关键字搜索',
                            data: function(){
                                return res.data
                            }
                        })

                        return resolve();
                    }
                });
            });
        }

        // 文件显示
        function fileShow(files) {
            let showFiles = {};
            layui.each(files, function(i, d) {
                if(d.field) {
                    if (showFiles[d.field]) {
                        showFiles[d.field].push(d);
                    } else {
                        showFiles[d.field] = [d];
                    }
                } else {
                    if (showFiles['kwfm']) {
                        showFiles['kwfm'].push(d);
                    } else {
                        showFiles['kwfm'] = [d];
                    }
                }
            });

            layui.each(showFiles, function(f, d) {
                let fileShowTpl = fileShowDemo.innerHTML
                    ,fileShow = document.getElementById('file-show-'+f);

                laytpl(fileShowTpl).render(d, function(html){
                    fileShow.innerHTML = html;
                });
            });
        }



        //数据渲染
        function pageInit(){
            getActivityOne({id:PageId}, function(res) {
                if(res.code === 1) {
                    let Activity = res.data;

                    form.val('infoForm', {
                        'data_version_id': Activity.data_version_id,
                        'is_published':Activity.is_published,
                        'name': Activity.name,
                        'begin_date': Activity.begin_date,
                        'date': Activity.date,
                        'periodical': Activity.periodical,
                        // 'is_published': Activity.is_published,
                        'is_core': Activity.is_core,
                        'is_wsjl': Activity.is_wsjl,
                        'wsjl_info': Activity.wsjl_info,
                        'other_paper': Activity.other_paper,
                        'is_awarded': Activity.is_awarded,
                        'award_from': Activity.award_from,
                        'level': Activity.level ? Activity.level_array[0].optionId : '',
                        'activity_category': Activity.activity_category,
                        'created_at': Activity.created_at
                    });
                    if(Activity.is_published == 2){
                        $('.is-fb').hide();
                        $('.is-hxqk').hide();
                    }
                    if(Activity.is_wsjl == 1) {
                        $("#wsjl-label").html('<i class="redstar">*</i>交流链接：');
                        // $("#wsjl-inline").removeClass('layui-hide');
                    }
                    if(Activity.is_core == 1) {
                        $("#isbn-code").html('<i class="redstar">*</i>ISBN编码：');
                        // $("#periodical-label").html('<i class="redstar">*</i>刊物名称：');
                    }
                    if(Activity.is_awarded == 1) {
                        $("#award-label").html('<i class="redstar">*</i>获奖时间：');
                        $("#award-label1").html('<i class="redstar">*</i>级别：');
                        $("#award-label2").html('<i class="redstar">*</i>颁奖机构：');
                        $(".award-link").removeClass("layui-hide");
                    }
                    form.val('checkForm', {
                        'form_instance_id': Activity.form_instance_id,
                        'status': Activity.instance.status,
                        'comment': Activity.instance.comment
                    });

                    // 创建人
                    if(Activity.creator){
                        var creatorName = '<button class="layui-btn layui-btn-primary" type="button">' + Activity.creator.nickname + '</button>';

                        $("#creator-show").append(creatorName);
                    }

                    //参与教师
                    xmDemo.setValue(Activity.participants_users.pant);
//文件
                    if(Activity.proof_material_array.length){
                        fileShow(Activity.proof_material_array);
                    }
                    $('input,select').prop('disabled', true);
                } else {
                    layer.msg('无数据记录', {time: 2000, icon: 5});
                }
            });
        }
    });
</script>
@endpush

@section('content')
<style>
    .layui-row{margin-bottom: 10px;}
    .opt-panel{padding: 10px;}
    .panel-title h3{margin-bottom: 20px;font-weight: 800;}

    .opt-form{padding: 20px 5px;}
    .opt-area{display: flex;flex-direction: row-reverse;padding: 10px 20px;margin-bottom: 20px;}
    .opt-area button, .back-btn{margin-left: 10px;}
</style>

<div class="layui-row">
    <div class="layui-panel opt-panel">
        <form class="layui-form opt-form" action="" id="info-form" lay-filter="infoForm">
            <div class="layui-row">
                <div class="panel-title">
                    <h3>文章发表 - 查看</h3>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>学年学期：</label>
                        <div class="layuik-input-inline">
                            <select class="data-version-id" name="data_version_id" lay-filter="termList" data-role="termList" lay-verify="required" lay-reqText="不能为空"></select>
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>论文名称：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="name" required lay-verify="required" placeholder="请输入" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>已发表：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" lay-filter="isPublished" name="is_published" title="是" value="1" class="layui-radio" lay-verify="otherReq">
                            <input type="radio" lay-filter="isPublished" name="is_published" title="否" value="2" class="layui-radio" lay-verify="otherReq">
                        </div>
                    </div>
                    <div class="layuik-inline is-fb">
                        <label class="layuik-form-label" id="publish-label">发表日期：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="begin_date" id="publish-date" placeholder="请选择" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two is-fb">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>核心期刊：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" lay-filter="isCore" name="is_core" title="是" value="1"  class="layui-radio">
                            <input type="radio" lay-filter="isCore" name="is_core" title="否" value="2"  class="layui-radio">
                        </div>
                    </div>
                    <div class="layuik-inline is-hxqk">
                        <label class="layuik-form-label" id="periodical-label"><i class="redstar">*</i>刊物名称：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="periodical"  placeholder="请输入" autocomplete="off" class="layui-input periodical">
                        </div>
                    </div>
                </div>

                <div class="layuik-form-item layuik-columns-two is-fb">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>已获奖：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" lay-filter="isAwarded" name="is_awarded" title="是" value="1"  class="layui-radio">
                            <input type="radio" lay-filter="isAwarded" name="is_awarded" title="否" value="2"  class="layui-radio">
                        </div>
                    </div>
                    <div class="layuik-inline award-link layui-hide">
                        <label class="layuik-form-label" id="award-label">获奖时间：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="date" id="award-date" placeholder="请选择" lay-reqText="不能为空" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two award-link layui-hide">
                    <div class="layuik-inline">
                        <label class="layuik-form-label" id="award-label1">级别：</label>
                        <div class="layuik-input-inline">
                            <select name="level" lay-filter="levelList" data-role="levelList"></select>
                        </div>
                    </div>
                    <div class="layuik-inline">
                        <label class="layuik-form-label" id="award-label2">颁奖机构：</label>
                        <div class="layuik-input-inline">
                            <input type="text" name="award_from"  placeholder="请输入" autocomplete="off" class="layui-input award_from">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>类别：</label>
                        <div class="layuik-input-inline">
                            <input type="radio" name="activity_category" value="EW_PAPER_PUBLISH_TABLE" title="教育" lay-verify="otherReq" class="layui-radio">
                            <input type="radio" name="activity_category" value="TEARRESEARCH_PUBLISH_TABLE" title="教学" lay-verify="otherReq" class="layui-radio">
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>参与教师：</label>
                        <div class="layuik-input-inline">
                            <div type="text" id="pter" class="xm-select-demo"></div>
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item layuik-columns-two">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>证明材料：</label>
                        <div class="layuik-input-inline">
                            <div id="file-show-kwfm"></div>
                        </div>
                    </div>
                </div>

            </div>
        </form>
    </div>
</div>


<div class="layui-row">
    <div class="layui-panel opt-panel">
        <form class="layui-form opt-form" action="" id="check-form" lay-filter="checkForm">
            <div class="layui-row">
                <div class="panel-title">
                    <h3>文章发表 - 审核</h3>
                </div>

                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label"><i class="redstar">*</i>审核结果：</label>
                        <div class="layuik-input-inline">
                            <input  type="radio" name="status" value="PASS" title="通过">
                            <input  type="radio" name="status" value="REVIEW_FAIL" title="驳回" >
                        </div>
                    </div>
                </div>
                <div class="layuik-form-item">
                    <div class="layuik-inline">
                        <label class="layuik-form-label">原因：</label>
                        <div class="layuik-input-inline">
                            <textarea  name="comment" placeholder="请输入内容" class="layui-textarea"></textarea>
                        </div>
                    </div>
                </div>
            </div>
            @if(!isset($_GET['hide']))
            <div class="layui-row">
                <div class="opt-area">
                    <a href="javascript:history.go(-1);" class="layui-btn layui-btn-primary back-btn">返回</a>
                    <input type="hidden" name="form_instance_id" value="0">
                </div>
            </div>
            @endif
        </form>
    </div>
</div>

<script id="fileShowDemo" type="text/html">
<ul>
@{{#  layui.each(d, function(index, item){ }}
@{{#  if(item){ }}
    <li style="min-width: 200px;margin: 13px 5px;">
        <a style="color: #0e90d2;" target="_blank" title="@{{item.file_info.file_name}}" href="@{{item.file_info.file_dir}}@{{item.file_info.file_path}}">
            <span style="display: inline-block;max-width: 90%;white-space:nowrap;overflow:hidden;text-overflow:ellipsis;">@{{item.file_info.file_name}}</span>
        </a>
        <a style="color:#74B8FF" href="@{{item.file_info.file_dir}}@{{item.file_info.file_path}}" download="@{{item.file_info.file_name}}">
            <span class="icon pear-icon pear-icon-download" style="color:#74B8FF;margin-left:10px;"></span>
        </a>
    </li>
@{{#  } }}
@{{#  }); }}
</ul>
</script>
@endsection
